package cz.cvut.fit.mi.dpo.mvc.view;

import cz.cvut.fit.mi.dpo.mvc.controller.Controller;
import cz.cvut.fit.mi.dpo.mvc.model.IModelChangedListener;
import cz.cvut.fit.mi.dpo.mvc.model.IReadable;

import javax.swing.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @author David Pertl
 * @author Martin Štekl <steklmar@fit.cvut.cz>
 */
public abstract class AView extends JPanel implements IModelChangedListener {

	private List<AView> subviews = new ArrayList<>();
	protected Controller controller;
	protected IReadable model;

	public AView(Controller controller, IReadable model) {
		this.controller = controller;
		this.model = model;
	}

	public void add(AView view) {
		add(view, null);
	}

	public void add(AView view, Object constraints) {
		super.add(view, constraints);
		subviews.add(view);
	}

	@Override
	public void fire() {
		for (AView view : subviews) {
			view.fire();
		}
		repaint();
	}

}
